﻿package com.tudou.home.newskin.panel
{
    import com.tudou.home.consts.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.containers.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.skin.*;
    import com.tudou.track.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;

    public class TopPanel extends Sprite implements ITransform, IVideoScale, IPlayer, IFullscreen
    {
        private var extendModuleEnable:Boolean;
        private var exitFull:ExitBTN;
        private var videoScale:VideoScale;
        private var background:DisplayObject;
        private var antiClockwise:InteractiveObject;
        private var clockwise:InteractiveObject;

        public function TopPanel()
        {
            background = RectDisplayUtil.getShape(PlayerConsts.MAIN_WIDTH, NewSkinConsts.TOP_PANEL_HEIGHT, 16711680, 0);
            addChild(background);
            videoScale = new VideoScale();
            addChild(videoScale);
            exitFull = new ExitBTN();
            addChild(exitFull);
            antiClockwise = new AntiClockwise();
            addChild(antiClockwise);
            clockwise = new Clockwise();
            addChild(clockwise);
            init();
            initListeners();
            return;
        }// end function

        public function setOriginalVideoScale(param1:Boolean) : void
        {
            videoScale.setOriginalVideoScale(param1);
            return;
        }// end function

        public function loading() : void
        {
            extendModuleEnable = false;
            return;
        }// end function

        public function paused() : void
        {
            return;
        }// end function

        private function mouseClickHlr(event:MouseEvent) : void
        {
            if (event.currentTarget == exitFull)
            {
                dispatchEvent(new SkinEvent(SkinEvent.SET_FULLSCREEN));
            }
            return;
        }// end function

        private function init() : void
        {
            this.useHandCursor = true;
            this.buttonMode = true;
            extendModuleEnable = false;
            videoScale.visible = false;
            exitFull.visible = false;
            antiClockwise.visible = false;
            clockwise.visible = false;
            return;
        }// end function

        private function initListeners() : void
        {
            this.addEventListener(MouseEvent.ROLL_OVER, rollOverOutHlr);
            this.addEventListener(MouseEvent.ROLL_OUT, rollOverOutHlr);
            clockwise.addEventListener(MouseEvent.CLICK, clockwiseHlr);
            antiClockwise.addEventListener(MouseEvent.CLICK, clockwiseHlr);
            exitFull.addEventListener(MouseEvent.CLICK, mouseClickHlr);
            return;
        }// end function

        private function rollOverOutHlr(event:MouseEvent) : void
        {
            if (extendModuleEnable == false)
            {
                return;
            }
            if (event.type == MouseEvent.ROLL_OVER)
            {
                videoScale.visible = true;
                antiClockwise.visible = true;
                clockwise.visible = true;
            }
            else
            {
                videoScale.visible = false;
                antiClockwise.visible = false;
                clockwise.visible = false;
            }
            return;
        }// end function

        private function clockwiseHlr(event:MouseEvent) : void
        {
            if (event.target == clockwise)
            {
                dispatchEvent(new SkinEvent(SkinEvent.SET_CLOCKWISE, true));
            }
            else
            {
                dispatchEvent(new SkinEvent(SkinEvent.SET_CLOCKWISE, false));
            }
            dispatchEvent(new SkinEvent(SkinEvent.BUTTON_LOG, SkinButtonCode.ROTATE));
            return;
        }// end function

        public function buffering() : void
        {
            return;
        }// end function

        public function setVideoScale(param1:Number) : void
        {
            videoScale.setVideoScale(param1);
            return;
        }// end function

        public function ready() : void
        {
            extendModuleEnable = false;
            return;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            background.width = param1;
            background.height = param2;
            exitFull.x = param1 - exitFull.width - 6;
            exitFull.y = 6;
            videoScale.x = exitFull.x - videoScale.width - 10;
            videoScale.y = exitFull.y;
            clockwise.x = videoScale.x - clockwise.width - 5;
            clockwise.y = videoScale.y;
            antiClockwise.x = clockwise.x - antiClockwise.width + 1;
            antiClockwise.y = clockwise.y;
            return;
        }// end function

        public function completed() : void
        {
            extendModuleEnable = false;
            videoScale.visible = false;
            antiClockwise.visible = false;
            clockwise.visible = false;
            return;
        }// end function

        public function playing() : void
        {
            extendModuleEnable = true;
            return;
        }// end function

        public function exitFullscreen() : void
        {
            exitFull.visible = false;
            return;
        }// end function

        public function enterFullscreen() : void
        {
            exitFull.visible = true;
            return;
        }// end function

    }
}
